﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<div class="search_form">
    <div class="text">
        <input id="search_txt" name="key" value="" class="keyword ac_input" size="25" maxlength="256"
            accesskey="Enter" style="width: 463px;" />
    </div>
    <div class="button">
        <input type="submit" title="Tìm kiếm" value="" name="search" id="search" onclick="test()"/>
    </div>
    <div class="clear">
    </div>
</div>
<script type="text/javascript" language="javascript">
    function test() {
        window.location = encodeURI("/Product/Products?keyword=" + document.getElementById('search_txt').value);
    }
    $(function () {

        $("#search_txt").autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "/Search/Search", type: "POST", dataType: "json",
                    data: { searchText: request.term, maxResults: 10 },
                    success: function (data) {
                        response($.map(data, function (item) {
                            return { label: item.Name, value: item.Name, id: item.View }
                        }))
                    }
                })
            },
            select: function (event, ui) {
                if (ui.item) {
                    window.location = encodeURI(ui.item.id);
                }
                else {
                    alert("Nothing selected, input was " + this.value);
                }
            }
        });

    });
</script>
